ActiveAdmin.register CourseStatistic do
  filter :company
  filter :store
  filter :course
  filter :date

  actions :index
  csv do
    column :date
    column :company
    column :course
    column :place
    column :queue
    column '总名额' do |stat|
      stat.place + stat.appointed
    end
    column '约课率' do |stat|
      number_to_percentage((stat.appointed*100 / (stat.place + stat.appointed) rescue 0), precision: 2)
    end
  end

  action_item :view, only: :index do
    link_to '查看图标', '#'
  end

  collection_action :import_csv, :method => :post do
    TimetableJob.perform_now(params[:csv][:data])
    redirect_to :action => :index, flash => "数据正在导入,请稍后查看"
  end


  index do
    column :date
    column :company
    column :course
    column :place
    column :queue
    column '总名额' do |stat|
      stat.place + stat.appointed
    end
    column '约课率' do |stat|
      number_to_percentage((stat.appointed*100 / (stat.place + stat.appointed) rescue 0), precision: 2)
    end
  end
end
